# -*- coding: utf-8 -*-
# File : single_thread.py
# Author: taoyahui
# Date : 2022/6/1
import requests
import re
import datetime
pattern = re.compile("<a href='problem.php\?id=\d+'>(.*?)</a>")

# 工作目标：爬取1-8页网页数据，获取标题信息
# 工作方式： 以单线程的方式执行


def main():
    for i in range(8):
        response = requests.get(f'http://10.10.74.125/problemset.php?page={i + 1}')
        html = response.text
        # print(html)
        # print("*" * 100)
        # 获取到了对应的标题名称
        result = pattern.findall(html)
        with open('result.txt', 'w') as f:
            for i in result:
                f.write(i + '\n')

if __name__ == '__main__':
    startTime = datetime.datetime.now()
    for i in range(100):
        main()
    endTime = datetime.datetime.now()
    print("运行时间：%s毫秒" % ((endTime - startTime).total_seconds() * 1000))


